package cn.sdhuijin.healthexam.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import cn.sdhuijin.healthexam.ExitApplication;
import cn.sdhuijin.healthexam.R;
import cn.sdhuijin.healthexam.control.AbstractControlActivity;
import cn.sdhuijin.healthexam.util.Constants;

/**
 * 新建人员档案
 * 
 * @author houyuchun
 * 
 */
public class EditPersonDocForthActivity extends AbstractControlActivity
		implements OnClickListener {

	// 创建日期ID
	private String createDate;
	// 家族史选项
	private int checkJiazushifuqinIds[] = { R.id.check_jibing_gaoxueya_fuqin,
			R.id.check_jibing_tangniaobing_fuqin,
			R.id.check_jibing_guanxinbing_fuqin,
			R.id.check_jibing_manxzsxingjb_fuqin,
			R.id.check_jibing_exingzhongliu_fuqin,
			R.id.check_jibing_naozuzhong_fuqin,
			R.id.check_jibing_jingshenbing_fuqin,
			R.id.check_jibing_jiehebing_fuqin, R.id.check_jibing_ganyan_fuqin,
			R.id.check_jibing_jixing_fuqin };

	private int checkJiazushimuqinIds[] = { R.id.check_jibing_gaoxueya_muqin,
			R.id.check_jibing_tangniaobing_muqin,
			R.id.check_jibing_guanxinbing_muqin,
			R.id.check_jibing_manxzsxingjb_muqin,
			R.id.check_jibing_exingzhongliu_muqin,
			R.id.check_jibing_naozuzhong_muqin,
			R.id.check_jibing_jingshenbing_muqin,
			R.id.check_jibing_jiehebing_muqin, R.id.check_jibing_ganyan_muqin,
			R.id.check_jibing_jixing_muqin };

	private int checkJiazushixiongdiIds[] = {
			R.id.check_jibing_gaoxueya_xiongdi,
			R.id.check_jibing_tangniaobing_xiongdi,
			R.id.check_jibing_guanxinbing_xiongdi,
			R.id.check_jibing_manxzsxingjb_xiongdi,
			R.id.check_jibing_exingzhongliu_xiongdi,
			R.id.check_jibing_naozuzhong_xiongdi,
			R.id.check_jibing_jingshenbing_xiongdi,
			R.id.check_jibing_jiehebing_xiongdi,
			R.id.check_jibing_ganyan_xiongdi, R.id.check_jibing_jixing_xiongdi };

	private int checkJiazushizinvIds[] = { R.id.check_jibing_gaoxueya_zinv,
			R.id.check_jibing_tangniaobing_zinv,
			R.id.check_jibing_guanxinbing_zinv,
			R.id.check_jibing_manxzsxingjb_zinv,
			R.id.check_jibing_exingzhongliu_zinv,
			R.id.check_jibing_naozuzhong_zinv,
			R.id.check_jibing_jingshenbing_zinv,
			R.id.check_jibing_jiehebing_zinv, R.id.check_jibing_ganyan_zinv,
			R.id.check_jibing_jixing_zinv };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 去掉标题
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_edit_doc_forth);
		ExitApplication.getInstance().addActivity(this);

		Intent intent = getIntent();
		// 创建日期ID
		Bundle bundle = intent.getBundleExtra("bundle");
		if (bundle != null) {
			createDate = bundle.getString("createDate");
		}
		setCurrentEditUserName(createDate);

		addCheckBoxView(checkJiazushifuqinIds, "家族病史_父亲");
		addEditTextView(R.id.edt_jiazushi_qita_fuqin, "其他家族病史_父亲");
		addCheckBoxView(checkJiazushimuqinIds, "家族病史_母亲");
		addEditTextView(R.id.edt_jiazushi_qita_muqin, "其他家族病史_母亲");
		addCheckBoxView(checkJiazushixiongdiIds, "家族病史_兄弟姐妹");
		addEditTextView(R.id.edt_jiazushi_qita_xiongdi, "其他家族病史_兄弟姐妹");
		addCheckBoxView(checkJiazushizinvIds, "家族病史_子女");
		addEditTextView(R.id.edt_jiazushi_qita_zinv, "其他家族病史_子女");

		// Properties文件路径
		controlManager.setPropertiesPath(Constants.PROPERTIES_PATH + createDate
				+ ".txt");
		Log.i(EditPersonDocThirdActivity.class.getSimpleName(), "文件路径： "
				+ Constants.PROPERTIES_PATH + createDate + ".txt");
		controlManager.toControl();

		setButtonListener(this, R.id.btn_next, R.id.btn_previous);
	}

	/**
	 * 按钮点击处理事件
	 */
	@Override
	public void onClick(View arg0) {
		Intent intent = new Intent();
		Bundle bundle = new Bundle();
		// 获取点击按钮
		int id = (Integer) arg0.getId();
		switch (id) {
		case R.id.btn_previous:
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			// 前一页按钮
			intent.setClass(this, EditPersonDocThirdActivity.class);
			startActivity(intent);
			this.finish();
			break;
		case R.id.btn_next:
			// 保存当前信息到Bean
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			// 前一页按钮
			intent.setClass(this, EditPersonDocLastActivity.class);
			startActivity(intent);
			this.finish();
			break;
		default:
			break;
		}
	}
}
